package com.lc1993929.tank;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;

/**
 * @author LiuChang
 * @date 2018/11/24 19:12
 */
@SpringBootApplication
public class TankApplication implements CommandLineRunner {

    public static void main(String[] args) {
        SpringApplication.run(TankApplication.class, args);
    }

    @Value("${server.port}")
    private Integer severPort;

    @Autowired
    private RestTemplate restTemplate;


    @Bean
    public RestTemplate restTemplate(RestTemplateBuilder builder) {
        return builder.build();
    }

    @Override
    public void run(String... strings) {
        if (severPort > 0) {
            try {
                restTemplate.getForEntity("http://localhost:" + severPort + "/player/init", null);
            } catch (Exception e) {
            }
        }
    }
}
